<!DOCTYPE html>
<html>
<head>
    <title>商品列表</title>
	<include file='public/head'></include>
	<style>
		.layui-legend-size{font-size:14px !important;}
		.layui-nopadding{padding:0 !important;}
		.layui-overflow{overflow:auto;}
		.layui-nomargin{margin: 0 !important;}
		.layui-bottom{border-bottom:1px solid rgb(226, 226, 226);}
		.layui-input{height:30px !important; }
		.layui-form-search-item .layui-inline{margin-bottom: 5px;}
		.layui-form-search-item label{margin-left: 15px;}
		.layui-table-page {padding: 7px 0px 0px;}
		.layui-field-padding{border-width: 1px;padding:0 0 5px 10px;}
	</style>
</head>
<body>
<!-- layui-tab开始 -->
<div class="layui-tab " lay-filter="demo-tab" class="js-check-wrap">
	<!-- 顶部导航菜单开始 -->
	<div class="layui-tab-nav" >
        <ul class="layui-tab-title">
			{:getNav('goods','admin_index/index')};
		</ul>
	</div>
	<form class="layui-form table-bar" action="{:cmf_plugin_url('Goods://admin_index/index')}" lay-filter="form-bar" method="post" id="search">
		<div style="padding:10px 0px 0px 0px ;">
			<button type="button" onclick="gosearch(100);" class="layui-btn <php>if($data['goods_type'] != "100"){echo "layui-btn-primary";}</php> ">
				全部商品({$goods_count.count1})
			</button>
			<button type="button" onclick="gosearch(1);" class="layui-btn <php>if($data['goods_type'] != "1"){echo "layui-btn-primary";}</php> ">
				已上架({$goods_count.count2})
			</button>
			<button type="button" onclick="gosearch(3);" class="layui-btn <php>if($data['goods_type'] != "3"){echo "layui-btn-primary";}</php> ">
				已下架({$goods_count.count4})
			</button>
			<button type="button" onclick="gosearch(2);" class="layui-btn <php>if($data['goods_type'] != "2"){echo "layui-btn-primary";}</php>  ">
				推荐商品({$goods_count.count3})
			</button>
		</div>
		<input type="hidden" name="goods_type" value="{$data.goods_type|default=''}">
		<!-- 顶部导航菜单结束 -->
		<fieldset class="layui-elem-field layui-field-title layui-field-padding">
			<legend class="layui-legend-size">搜索</legend>
				<div class="layui-form-search-item">
					{$searchStr}
					<button type="submit" class="layui-btn layui-btn-sm layui-btn-primary" id="searche_btn" style="font-weight:800;" lay-submit="" lay-filter="demo2"><i class="layui-icon ">&#xe615;</i>搜索</button>
				</div>
		</fieldset>
	</form>
	<!-- 表格内容开始 -->
	<div class="layui-card">
		<div class="layui-card-header layui-bg-gray layui-bottom" id="piliang">
			<!-- <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-danger batch-delete" onclick="allDelete()"><i class="layui-icon">&#xe640;</i>批量删除</a> -->
			批量操作
			<select v-model="selected" lay-verify="required" style="height:24px;font-size:13px" @change='getValue'>
				<option value="1">下架</option>
				<option value="2">上架</option>
				<option value="3">取消推荐</option>
				<option value="4">设为推荐</option>
				<option value="5">批量删除</option>
			</select>
			<a href="{:cmf_plugin_url('Goods://admin_index/addGoods')}" class="layui-btn layui-btn-xs " ><i class="layui-icon">&#xe654;</i>添加</a>
<!--			<a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-normal daochu" ><i class="layui-icon">&#xe67d;</i>导出</a>-->
		</div>
		<div class="layui-card-body layui-nopadding " >
			<form method="post" id="f">
			<table  class="layui-table layui-nomargin" >
				<!-- 表格头 -->
				<thead>
					<tr>
						<th width="20px" style="text-align:center;">
                            <input type="checkbox"  id="check-box-all" >
                        </th>
						<php>
							//输出表格头
							echo $table->getHeader();
						</php>
						<th style="text-align:center;"><b>商品状态</b></th>
						<th style="text-align:center;"><b>操作</b></th>
					</tr>
				</thead>
				<!-- 表格内容输出 -->
				<volist name="list" id="vo" >
					<tr <?php if ($vo['is_spec_warning'] == true){echo 'style="background:#CD5C5C"';} ?> >
						<th style="text-align:center;">
                            <input type="checkbox" class="check-box " name="id[]" value="{$vo['id']}">
                         </th>
						<php>
							echo $table->createHtml($vo);
						</php>
						<td>
							上架状态：
							<if condition="$vo.status == 1 && $vo.audit_status == 2">
								<span class="layui-btn layui-btn-radius layui-btn-xs good-change" data-id='{$vo.id}' data-type='1'>是</span>
							<else />
								<span class="layui-btn layui-btn-danger layui-btn-radius layui-btn-xs good-change" data-id='{$vo.id}' data-type='2'>否</span>
							</if>
							<br>
							<if condition="$vo.status == 1 && $vo.audit_status == 2">
								推荐状态：
								<if condition="$vo.referr_status == 1">
									<span class="layui-btn layui-btn-radius layui-btn-xs good-change" data-id='{$vo.id}' data-type='3'>是</span>
								<else />
									<span class="layui-btn layui-btn-danger layui-btn-radius layui-btn-xs good-change" data-id='{$vo.id}' data-type='4'>否</span>
								</if>
							</if>
						</td>
						<td width="120px" >
							<if condition="$vo['is_spec_warning'] == true">
								<span>库存预警</span>
							</if>
							<div class="layui-btn-group">
								<a href="{:cmf_plugin_url('Goods://admin_index/editGoods')}?id={$vo.id}" class='layui-btn layui-btn-xs layui-btn-primary update-btn' title='编辑'><i class='layui-icon'>&#xe642;</i></a>
								<button type='button' class='layui-btn layui-btn-xs layui-btn-primary delete-btn' style='font-weight:800 ;' data-id='{$vo.id}' title='删除'><i class='layui-icon'>&#xe640;</i></button>
								<a href="{:cmf_plugin_url('Goods://admin_index/goodsDetail')}?id={$vo.id}" class='layui-btn layui-btn-xs layui-btn-primary update-btn' title='查看'><i class='layui-icon'>&#xe602;</i></a>
								<php>
									//判断规格插件有没有安装
									$plugin = new \app\common\lib\user_operate\PluginOperate;
									$is_install = $plugin->isInstall('goods','GoodsSpec');
								</php>
								<if condition="$is_install === true">
									<a href="javascript:;" data-id="{$vo.id}" class='layui-btn layui-btn-xs layui-btn-primary spec-detail' title='规格详情'><i class='layui-icon'>&#xe610;</i></a>
									<br>

								</if>
							</div>
						</td>
					</tr>
				</volist>
				<!-- 表格内容输出结束 -->
			</table>
			</form>
			<div class="layui-table-page">
				<div id="layui-table-page1">
					<div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-1">
						{$page|default=''}
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<!-- layui-tab结束-->
<include file='public/scripts'></include>
<script type="text/javascript">
var vm = new Vue({
  	el: '#piliang',
  	data: {
  		selected: ''
  	},
  	methods: {
  		getValue: function(){
           	let this_ = this
  			let da = $('#f').serialize();
  			let url = "{:cmf_plugin_url('Goods://admin_index/pilaing')}?type="+this_.selected;
		    var text = "确定要执行此操作吗？";
		    layer.confirm(text, {icon: 3, title:'提示', btn: ['确定','取消']}, function(index,layero){
	  			$.ajax({
		            url:url,
		            data:da,
		            type:'post',
		            success:function(data){
		                if (data.code == 1) {
		                    layer.msg(data.msg,{icon:1,time:1500},function(){
		                        window.location.reload();
		                    });
		                } else {
		                    layer.msg(data.msg,{icon:2,time:1500});
		                }
		            },
		            error:function(){
		                layer.msg('系统错误',{icon:2,time:1500});
		            }
		        })
		    },function(index){
		        // alert('取消');
		    });
        }
  	}
})
$('.good-change').on('click',function(){
	let id = $(this).data('id');
	let type = $(this).data('type');
	let url = "{:cmf_plugin_url('Goods://admin_index/pilaing')}";
    var text = "确定要执行此操作吗？";
    layer.confirm(text, {icon: 3, title:'提示', btn: ['确定','取消']}, function(index,layero){
		$.ajax({
		    url:url,
		    data:{'id':id,'type':type},
		    type:'post',
		    success:function(data){
		        if (data.code == 1) {
		            layer.msg(data.msg,{icon:1,time:1500},function(){
		                window.location.reload();
		            });
		        } else {
		            layer.msg(data.msg,{icon:2,time:1500});
		        }
		    },
		    error:function(){
		        layer.msg('系统错误',{icon:2,time:1500});
		    }
		})	
    },function(index){
        // alert('取消');
    });
});
//导出
$('.daochu').on('click', function(){
	var text = "确定要导出吗？";
    var da = $('#search').serialize();
    var f = $('#f').serialize();
    da += "&daochu=1" + "&"+f;
    let url = "{:cmf_plugin_url('Goods://admin_index/index')}";
	layer.confirm(text, {icon: 3, title:'提示', btn: ['确定','取消']}, function(index,layero){
        $.ajax({
            url:url,
            type:'post',
            data:da,
            success:function(data){
                if (data.code==1) {
                    var $a = $("<a>");
                    $a.attr("href", data.data.file);
                    $a.attr("download", data.data.filename);
                    $("body").append($a);
                    $a[0].click();
                    $a.remove();
                } else {
                    layer.msg(data.msg,{icon:2,time:1500});
                }
            },
            error:function(){
                layer.msg('系统错误',{icon:2,time:1500});
            }
        })
    },function(index){
        // alert('取消');
    });
})
var gosearch = function( value ){
	$('input[name=goods_type]').val( value );
	$( '#searche_btn' ).click();
}
//规格详情
$('.spec-detail').on('click',function(){
	let id = $(this).data('id');
	let url = "{:cmf_plugin_url('Goods://goods_spec/goodsSpecDetail')}?id="+id;
	layer.open({
		type:2
		,title:"规格详情"
		,shadeClose: true//是否点击遮罩关闭
		,area:['1000px','750px']
		,shade:0.8
		,id:'LAY_article'
		,btn:['提交']
		,content:url
		,moveType:1,
		yes:function(index, layero){
			var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
			iframeWin.tijiao();
		}
	});
})
function allDelete(){
	var text = "确定要删除吗？";
    var da = $('#f').serialize();
    let url = "{:cmf_plugin_url('Goods://admin_index/delGoods')}";
	layer.confirm(text, {icon: 3, title:'提示', btn: ['确定','取消']}, function(index,layero){
        $.ajax({
            url:url,
            data:da,
            success:function(data){
                if (data.code == 1) {
                    layer.msg(data.msg,{icon:1,time:1500},function(){
                        window.location.reload();
                    });
                } else {
                    layer.msg(data.msg,{icon:2,time:1500});
                }
            },
            error:function(){
                layer.msg('系统错误',{icon:2,time:1500});
            }
        })
    },function(index){
        // alert('取消');
    });
}
$(function(){
	 //全选/取消
    $('#check-box-all').on('click',function(){	
        console.log(1111);
        $('.check-box').prop('checked',$('#check-box-all').prop('checked'));
    });
	$('.delete-btn').on('click',function(){
		var text = "确定要删除吗？";
        let id = $(this).data('id');
        let url = "{:cmf_plugin_url('Goods://admin_index/delGoods')}";
		layer.confirm(text, {icon: 3, title:'提示', btn: ['确定','取消']}, function(index,layero){
            $.ajax({
                url:url,
                data:{id:id},
                success:function(data){
                    if (data.code == 1) {
                        layer.msg(data.msg,{icon:1,time:1500},function(){
                            window.location.reload();
                        });
                    } else {
                        layer.msg(data.msg,{icon:2,time:1500});
                    }
                },
                error:function(){
                    layer.msg('系统错误',{icon:2,time:1500});
                }
            })
        },function(index){
            // alert('取消');
        });
	})
})
</script>
</body>
</html>